package com.example.wjh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.wjh.entity.TrainingSchedule;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TrainingScheduleMapper extends BaseMapper<TrainingSchedule> {

    // 根据ID获取训练安排
    @Select("SELECT * FROM trainingschedule WHERE id = #{id}")
    TrainingSchedule selectById(@Param("id") Long id);

    // 插入新的训练安排
    @Insert("INSERT INTO trainingschedule (playerName, coachName, trainingDate, trainingTime, trainingLocation, trainingContent, status) " +
            "VALUES (#{playerName}, #{coachName}, #{trainingDate}, #{trainingTime}, #{trainingLocation}, #{trainingContent}, #{status})")
    int insertTrainingSchedule(TrainingSchedule trainingSchedule);

    // 更新训练安排
    @Update("UPDATE trainingschedule SET playerName = #{playerName}, coachName = #{coachName}, " +
            "trainingDate = #{trainingDate}, trainingTime = #{trainingTime}, trainingLocation = #{trainingLocation}, " +
            "trainingContent = #{trainingContent}, status = #{status} " +
            "WHERE id = #{id}")
    int updateTrainingSchedule(TrainingSchedule trainingSchedule);

    // 根据ID删除训练安排
    @Delete("DELETE FROM trainingschedule WHERE id = #{id}")
    int deleteById(@Param("id") Long id);

    // 获取所有训练安排
    @Select("SELECT * FROM trainingschedule")
    List<TrainingSchedule> getAllTrainingSchedules();

    // 多条件查询
    @Select("<script> " +
            "SELECT * FROM trainingschedule " +
            "<where> " +
            "<if test='playerName != null'> AND playerName LIKE CONCAT('%', #{playerName}, '%')</if> " +
            "<if test='coachName != null'> AND coachName LIKE CONCAT('%', #{coachName}, '%')</if> " +
            "<if test='trainingLocation != null'> AND trainingLocation LIKE CONCAT('%', #{trainingLocation}, '%')</if> " +
            "<if test='status != null'> AND status = #{status}</if> " +
            "</where> " +
            "</script>")
    List<TrainingSchedule> searchTrainingSchedules(
            @Param("playerName") String playerName,
            @Param("coachName") String coachName,
            @Param("trainingLocation") String trainingLocation,
            @Param("status") String status);

}
